<?php


namespace App\Utils\Notice;


use App\Model\NoticeCooperative;

class CooperativeAuditReturn extends Notice
{

    public $messageTemplate = '您好，合作商资料审核失败，请重新提交，原因如下：“%message%”';

    //前端路由-微信支付参数填写页面
    public $routeName = 'InitPay';

    public function toDatabase()
    {
        $data = $this->format($this->data);
        /** @var NoticeCooperative $model */
        $model = new NoticeCooperative();
        $model->fill($data)->save();
    }

    public function format($data)
    {

        $return = [
            'cooperative_user_id' => $this->receiverId,
            'content' => $this->messageTemplate,
            'type' => \App\Constants\Model\Notice::COOPERATIVE_AUDIT_RETURN,
            'extension' => [
                'path' => $this->routeName
            ]
        ];

        $searches = [];
        foreach ($data['replaces'] as $replace => $content) {
            $searches[] = '%' . $replace . '%';
        }
        $return['content'] = str_replace($searches, $data['replaces'], $this->messageTemplate);

        return $return;
    }
}